package com.pkk.penguin.frame.know.java.interview.singleton;

/**
 * @description: 多线程版的赖汉师单例模式
 * @author: peikunkun
 * @create: 2019-12-28 18:05
 **/
public class SingletonInterview3 {

  private static SingletonInterview3 singletonInterview3 = null;

  public static SingletonInterview3 getInstance() {
    //这一步为什么还要判断,是因为锁资源和等待锁是比较耗时间的,而大部分次数singletonInterview3都是不为空的,都是直接可以返回的,所以没有必要去锁
    if (null == singletonInterview3) {
      //锁对象
      synchronized (SingletonInterview3.class) {
        if (null == singletonInterview3) {
          singletonInterview3 = new SingletonInterview3();
        }
      }
    }
    return singletonInterview3;
  }

}
